<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script>
    $(function () {       
		$('#backid').click(function(){
				window.location.href="index.html";
		 });
    });
</script>
</head>
<body>
<form action="index.html" method="post" class="definewidth m20" id="addForm" >
    <input type="hidden" name="resourceId" value=""/>
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">资源名称</td>
            <td><input id="resourceName" type="text" name="resourceName"/></td>
        </tr>
        <tr>
            <td class="tableleft">url</td>
            <td><input id="resourceUrl" type="password" name="url"/></td>
        </tr>
        <tr>
            <td class="talbleleft">父级资源：</td>
            <td>
                <select name="parentMenu" id="parentMenu">
                    <option id="def">-</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">是否有效</td>
            <td>
                <input type="radio" name="resourceState" value="0" checked/> 有效
                <input type="radio" name="resourceState" value="1" /> 无效
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <button type="button" class="btn btn-primary" type="button" id="updateResource">更新</button>&nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script>
    $(function () {
        loadPreMenu();
        $("#updateResource").click(function () {
            /*表单验证*/
            var reName = $("#resourceName").val();
            var reUrl = $("#resourceUrl").val();
            if (reName==null || reName==""){
                alert("请填写资源名称");
                return;
            }
            if (reUrl==null || reUrl==""){
                alert("请填写url路径");
                return;
            }
            $.ajax({
                type:"POST",
                url:"/resource/",
                data:$("#addForm").serialize(),
                dataType:"json",
                success: function(vo){
                    if (vo.code==200){
                        window.location.href="index.html";
                    }else {
                        alert(vo.msg);
                    }
                }
            });
        });

        function loadPreMenu(){
            $.ajax({
                type:"GET",
                url:"/resource/parent",
                data:"",
                dataType: "json",
                success: function (vo) {
                    if(vo.code==200) {
                        var list = vo.list;
                        var str = "";
                        for (var i = 0; i < list.length; i++) {
                            var obj = list[i];
                            str += "<option value='" + obj.resourceId + "'>" + obj.resourceName + "</option>"
                        }
                        $("#parentMenu").html(str);
                    }else {
                        $("#def").html(vo.msg);
                    }
                }
            });
        }
    });
</script>
</html>